package com.lzq.leetcode.lanqiao;

import java.util.Arrays;
import java.util.Scanner;

public class s3142 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt();
        int k = scan.nextInt();
        long[] nums = new long[n];

        for (int i=0; i<n; i++) {
            nums[i] = scan.nextLong();
        }
        // 排序
        Arrays.sort(nums);

        // 计算前缀和
        long[] sum = new long[n+1];
        for (int i=1; i<=n; i++) {
            sum[i] = sum[i-1] + nums[i-1];
        }
        // 遍历计算
        long min = Long.MAX_VALUE;
        for (int p=1; p<=k; p++) {
            min = Math.min(min, (long)sum[p * 2] + sum[n] - sum[n-k+p]);
        }
        System.out.println(min);
        scan.close();
    }
}
